package com.syf.starter.core;

import com.syf.core.engine.SyFrameContext;
import com.syf.core.server.SyServer;
import com.syf.starter.config.SyHttpServerConfiguration;
import com.syf.starter.core.netty.SyNettyHttpServer;
import com.syf.starter.core.netty.SyNettyServerConfig;

import java.util.concurrent.CountDownLatch;

public class SyHttpServer implements SyServer {
    private final SyNettyHttpServer server;

    public SyHttpServer(SyHttpServerConfiguration configuration, SyFrameContext syFrameContext) {
        server = new SyNettyHttpServer(configuration, syFrameContext);

        SyNettyServerConfig config = new SyNettyServerConfig();
        config.setServerName(configuration.getServerName());
        config.setHost(configuration.getHost());
        config.setPort(configuration.getPort());
        server.initServer(config);
    }

    @Override
    public void startup(CountDownLatch latch) {
        server.startServer(latch);
    }

    @Override
    public void gracefullyShutdown() {
        server.stopServer();
    }
}
